﻿
Imports System.IO
Imports System.Drawing

Partial Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub cmdLookUp_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdLookUp.Click

        Try

            If txtPaketIdentNr.Text.Trim.Length <= 0 Then Exit Sub

            Dim PTS As New PaketTrackerService.Webservices

            Dim PS As PaketTrackerService.PaketStatus = Nothing

            'test
            'txtBeschreibung.Text = PTS.Test("Hallo Kai")

            '3ICK920PFOISXO3
            '64509723
            '4IQI4SB74D60KPO mit Bild
            '4DNM8GA9MI668X4 auch mit Bild
            PS = PTS.GetPaketStatus(txtPaketIdentNr.Text)
            If PS Is Nothing Then Throw New Exception("Die PaketIdent ist nicht bekannt !")

            txtBeschreibung.Text = PS.Beschreibung
            txtStatus.Text = PS.Status.ToString

            SaveBytetoPNG(PS.MapImage, "C:\temp.png")
            imPaketPlace.ImageUrl = "C:\temp.png"

        Catch ex As Exception

            txtBeschreibung.Text = ""
            txtStatus.Text = ""
            imPaketPlace.ImageUrl = ""

            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
        End Try

    End Sub

    Private Shared Sub SaveBytetoPNG(ByVal image__1 As Byte(), ByVal name As String)
        If image__1 IsNot Nothing AndAlso image__1.Length > 0 Then
            Dim ms As New MemoryStream(image__1)
            Dim returnImage As Image = Image.FromStream(ms)

            returnImage.Save(name, Imaging.ImageFormat.Png)
        End If
    End Sub


End Class